<?php

declare(strict_types=1);

namespace App\AdminApi\Modular\Data\Validate;

use App\Common\Modular\Data\Enums\ResourcesCateState;
use Core\Constants\Database;
use Zms\Validate\ValidateAbstract;
use JetBrains\PhpStorm\ArrayShape;

/**
 * 资源分类验证器
 */
class ResourcesCateValidate extends ValidateAbstract
{
    public function rules(): array
    {
        return [
            ['id', 'required', 'error' => '数据异常，请刷新重试', 'on' => ['updated']],
            ['id', 'number', 'error' => '数据异常，请刷新重试', 'on' => ['updated']],

            ['type', 'required', 'error' => '数据错误，请刷新重试', 'on' => ['created']],
            ['type', 'in', 'enums' => ResourcesCateState::Values(ResourcesCateState::TAG['TYPE']), 'error' => '数据错误，请刷新重试', 'on' => ['created']],

            ['name', 'required', 'error' => '请输入{label}', 'on' => ['created', 'updated']],
            ['name', 'string', 'max' => 10, 'error' => '{label}错误', 'on' => ['created', 'updated']],

            ['sort', 'number', 'min' => Database:: INT_MIN, 'max' => Database::INT_MAX, 'precision' => 0, 'on' => ['created', 'updated']],
        ];
    }


    #[ArrayShape(['name' => "string", 'sort' => "string"])]
    public function labels(): array
    {
        return [
            'name' => '分类名称',
            'sort' => '菜单排序',
        ];
    }
}